package com.xm.servlet.reception_desk.shopping_cart;

import com.xm.service.reception_desk.ShoppingCartService;
import lombok.SneakyThrows;


import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * 修改购物车数量
 * @author 康文程
 * @date 2024-1-3 上午 09:40
 */
@WebServlet("/modify/shopping/cart/number")
public class ModifyShoppingCartNumberServlet extends HttpServlet {
    private final ShoppingCartService service = new ShoppingCartService();

    /**
     * 修改购物车状态
     * @param req   the {@link HttpServletRequest} object that
     *                  contains the request the client made of
     *                  the servlet
     *
     * @param resp  the {@link HttpServletResponse} object that
     *                  contains the response the servlet returns
     *                  to the client
     *
     */
    @SneakyThrows(Exception.class)
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
        req.setCharacterEncoding("UTF-8");
        String shoppingCartId = req.getParameter("shoppingCartId");
        System.out.println(shoppingCartId);
        String quantity = req.getParameter("quantity");
        System.out.println(quantity);
        resp.getWriter().println(service.updateQuantity(Integer.parseInt(shoppingCartId),
                Integer.parseInt(quantity)));

    }
}
